package com.hhkj.study.common.controller;

import com.hhkj.study.common.model.req.UserWechatReq;
import com.hhkj.study.common.model.res.AliyunOssRes;
import com.hhkj.study.common.service.CommonService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.login.api.ApiLoginOpen;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author luowu
 * @Date 2024/9/12 涵 9:43:02
 */
@RestController
@RequestMapping("/api/common")
public class BusinessCommonController {

    @Resource
    private CommonService commonService;

    /**
     * 文件上传
     * @param fileList
     * @return
     */
    @ApiLoginOpen
    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("fileList") List<MultipartFile> fileList) {
        List<AliyunOssRes> aliyunOssResultList = commonService.uploadBatch(fileList);
        return AjaxResult.success(aliyunOssResultList);
    }

    /**
     * 检查用户是否添加微信企业客服
     * @return
     */
    @PostMapping("/check/user/wechat")
    public AjaxResult checkUserWechat(@RequestBody @Validated UserWechatReq req) {
        return AjaxResult.success(commonService.checkUserWechat(req));
    }

    /**
     * 生成小程序码 通过临时标识
     * @return
     */
    @ApiLoginOpen
    @GetMapping("/getQrUrl/{scene}")
    public AjaxResult getQrUrl(@PathVariable("scene") String scene) {
        return AjaxResult.success(commonService.generateQrCode(scene));
    }
}
